#include "menu.h"

int Menu::drawMenu(bool isroot)
{
    system("clear");
    lines.clear();
    if(isroot)
    {
        lines.push_back("\033[01;35m-------------------------------------------------------------------");
        lines.push_back("|                      Student Manage System                      |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|                            Main Menu                            |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|       \033[01;31m1.Login mannage \033[01;35m         |           \033[01;31m2.Student mannage\033[01;35m    |");
        lines.push_back("|-----------------------------------------------------------------|");
        lines.push_back("|      \033[01;31m3.Subjects mannage\033[01;35m        |         \033[01;31m 4.Switch account\033[01;35m      |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|        \033[01;31m                  5.Exit System                  \033[01;35m        |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|\033[01;31mYour chosen:[1/2/3/4/5]:                                         \033[01;35m|");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|\033[01;31mPress Enter to continue...                                       \033[01;35m|");
        lines.push_back("-------------------------------------------------------------------\033[0m");
    }
    else
    {
        lines.push_back("\033[01;35m-------------------------------------------------------------------");
        lines.push_back("|                      Student Manage System                      |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|                            Main Menu                            |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|      \033[01;31m1.Change Password \033[01;35m        |           \033[01;31m2.My Subjects\033[01;35m        |");
        lines.push_back("|-----------------------------------------------------------------|");
        lines.push_back("|       \033[01;31m3.Select Subjects\033[01;35m        |         \033[01;31m  4.Drop Subjects\033[01;35m      |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|       \033[01;31m5.Switch Account  \033[01;35m       |          \033[01;31m 6.Exit System\033[01;35m        |");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|\033[01;31mYour chosen:[1/2/3/4/5/6]:                                       \033[01;35m|");
        lines.push_back("-------------------------------------------------------------------");
        lines.push_back("|\033[01;31mPress Enter to continue...                                       \033[01;35m|");
        lines.push_back("-------------------------------------------------------------------\033[0m");
    }

    for(auto a : lines) std::cout << a << std::endl;

    moveCursor('u', 4);
    moveCursor('r', 25 + (isroot ? 0 : 2));
    std::string strret;
    strret = readCommand();
    int ret = isDigit(strret);
    if(ret > (5 + !isroot) || ret < 1) 
    {
        system("clear");
        std::cout << "\n\n\t\t\033[01;35mNo Such Option, Please Try Again.\033[0m" << std::endl;
        sleep(2);
        return drawMenu(isroot);
    }
    else return ret;
}